package dongwu;

import java.util.Random;

public class Animal {
	int x, y;
	String Varieties;
	

	void move() {
		x = movex();
		y = movey();
	}

	void display() {
		if ((x > 0 && x < 10) && (y > 0 && y < 10)) {
			System.out.println(Varieties + "的当前坐标为：(" + x + "," + y + ")");
		} else {
			System.out.print("出界!重新生成" + Varieties + "的位置!");
			firstx();
			firsty();
			display();
		}
	}

	int movex() {
		Random random = new Random();
		int a = random.nextInt(2);
		if (a == 0) {
			x++;
			return x;
		}
		if (a == 1) {
			x--;
			return x;
		}
		return x;
	}

	int movey() {
		Random random = new Random();
		int a = random.nextInt(2);
		if (a == 0) {
			y++;
			return y;
		}
		if (a == 1) {
			y--;
			return y;
		}
		return y;
	}

	public int firstx() {
		x = (int) (Math.random() * 10);
		return x;

	}

	int firsty() {
		y = (int) (Math.random() * 10);
		return y;
	}

}
